<?php

/**
 *
 * PHP API 商品属性控制器
 * @author jeff
 * powered by jeff liu 2011-06-08
 */
class Goods_proApp extends ApiApp
{
    public $_goods_pro_mod;

    function __construct()
    {
        $this->Goods_proApp();
    }

    function Goods_proApp()
    {
        parent::__construct();
        $this->_goods_pro_mod =& api_model('goodspro');
    }

    /**
     * 获得商品某个属性的详细信息
     * @goods_id float required 商品ID
     * @pro_id   float required 属性ID
     * powered by jeff 2011-6-8
     */
    function apiGetGoodsProDetail()
    {
        $goods_id = $_REQUEST['goods_id'];
        $pro_id = $_REQUEST['pro_id'];
        if (empty($goods_id)) {
            $error = ApiError::showError('goods_id_required', 1);
            echo $error;
            return;
        }

        if (empty($pro_id)) {
            $error = ApiError::showError('pro_id_required', 1);
            echo $error;
            return;
        }
        $field = '*';
        $sql = sprintf(
            'SELECT %s.%s FROM %s %s WHERE %s.goods_id=%.0f AND pro_id=%.0f',
            $this->_goods_pro_mod->alias,
            $field,
            $this->_goods_pro_mod->table,
            $this->_goods_pro_mod->alias,
            $this->_goods_pro_mod->alias,
            (float)$goods_id,
            (float)$pro_id
        );
        $result = $this->_goods_pro_mod->getOne($sql);
        $result = array('data' => $result);
        $result = $this->echo_result($result);
    }

    /**
     * 获得商品所有属性的详细信息
     * @id float required 商品ID
     * powered by jeff 2011-6-8
     */
    function apiGetGoodsProListByGoodsId()
    {
        $goods_id = $_REQUEST['id'];
        if (empty($goods_id)) {
            $error = ApiError::showError('goods_id_required', 1);
            echo $error;
            return;
        }
        $field = '*';
        $sql = sprintf(
            'SELECT %s.%s FROM %s %s WHERE %s.goods_id=%.0f',
            $this->_goods_pro_mod->alias,
            $field,
            $this->_goods_pro_mod->table,
            $this->_goods_pro_mod->alias,
            $this->_goods_pro_mod->alias,
            (float)$goods_id
        );
        $result = $this->_goods_pro_mod->getAll($sql);
        $result = array('data' => $result);
        $this->echo_result($result);
    }

}